//TOWN SCRIPT TEMPLATE

begintownscript;

variables;
short i,j,k;
string dlgstr;

body;

beginstate INIT_STATE;
	set_crime_tolerance(1);

if ((get_flag(3,1) != 1) && (get_flag(3,1) != 3)) {
	force_instant_terrain_redraw();
	message_dialog("This cave smells like goblins, and one of the members of your party is deathly afraid of goblins. You cannot force her to enter unless you have a compelling reason to do so.","");
	end();
	}

if (get_flag(6,4)) {
	erase_char(10);
	erase_char(11);
	erase_char(12);
	erase_char(13);
	erase_char(14);
	erase_char(15);
	}

if (get_flag(6,0) == 0) {
	set_flag(6,0,1);
	force_instant_terrain_redraw();
	message_dialog("You enter the cave. The residents are unmistakable: it is dank, dark, and smelly. Definitely a goblin cave. Machrone's box should be in here somewhere.","Your third party member starts to protest that she hates goblins, but you quiet her down; you have no choice but to go inside. She does keep muttering to herself as you enter. That can't be good.");
	}
break;

beginstate EXIT_STATE;
//called when the party leaves the town
	text_bubble_on_char(0,"");
	text_bubble_on_char(1,"");
	text_bubble_on_char(2,"");
	text_bubble_on_char(3,"");

break;

beginstate START_STATE;
//called every turn when the party is in the town
if (get_flag(6,1) == 0) {
	if (get_ran(1,0,100) < 3)
		text_bubble_on_char(2,"Goblins are scary!");
	if (get_ran(1,0,100) < 3)
		text_bubble_on_char(2,"I don't like this!");
	if (get_ran(1,0,100) < 3)
		text_bubble_on_char(2,"I wanna go home!");
	}
if (get_flag(6,1) == 1) {
	set_char_status(2,30,20,1,0);
	if (get_ran(1,0,100) < 40)
		text_bubble_on_char(2,"EEK!");
	}
if (get_flag(6,1) == 2) {
	if (get_ran(1,0,100) < 7)
		text_bubble_on_char(2,"*sob*");
	}
break;

beginstate 10;
if (get_flag(6,1) == 0) {
	
	while (i < 119) {
	if (char_ok(i))
		text_bubble_on_char(i,"");
	i = i + 1;
	}

	set_flag(6,1,1);
	block_entry(1);
	message_dialog("By now, the third member of your party is near tears. Not seeing any goblins does not make it any easier for her to walk through goblin-infested caves. But then, suddenly, you hear noise behind you!","You are suddenly surrounded by goblins! It's an ambush!");

	activate_hidden_group(1);	
	text_bubble_on_char(2,"EEEK!!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(2,"");
	force_instant_terrain_redraw();

	set_char_status(2,30,20,1,0);
	
	clear_buffer();
	append_char_name(2);
	append_string(" is completely horrified. Before you can say anything, she starts screaming and running away.");
	get_buffer_text(dlgstr);
	message_dialog(dlgstr,"You may have to fight this battle without her.");
	}
break;

beginstate 11;
if (get_flag(6,2) == 0) {
	
	while (i < 119) {
	if (char_ok(i))
		text_bubble_on_char(i,"");
	i = i + 1;
	}

	set_flag(6,2,1);
	block_entry(1);
	text_bubble_on_char(0,"Smells funny this way.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(0,"");
	text_bubble_on_char(3,"I hope we've saved.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(3,"");
	text_bubble_on_char(0,"What?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(0,"");
	text_bubble_on_char(3,"Nothing.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	force_instant_terrain_redraw();
	}
break;

beginstate 12;
if (get_flag(6,3) == 0) {
	set_flag(6,3,1);
	message_dialog("You hear shouting and blasts of fire on the other side of this door. Something must be going on in there.","");
	}
break;

beginstate 13;
if (get_flag(6,4) == 0) {
	set_flag(6,4,1);
	block_entry(1);
	
	while (i < 119) {
	if (char_ok(i))
		text_bubble_on_char(i,"");
	i = i + 1;
	}

i = 10;
while (i <= 27) {
	set_character_pose(i,2);
	i = i + 1;
	}
	force_instant_terrain_redraw();

	message_dialog("On the other side of this door, you see a battle! Ready for glory, you begin to charge into the midst of it, intending to defeat the villains and conquer all that stands in your path!","");
	
	march_party(19,22);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));

	message_dialog("Then you look around and notice who's fighting the battle. It's the same six adventurers you met in the inn in Pleasant Town, the ones who asked just Look, Name, and Job, and walked away.","They have grown dramatically in power since you last saw them, and they don't look as though they need help.");
	
	put_effect_on_char(17,12,1,2);
	set_character_pose(10,1);
	run_animation_sound(69);
	set_character_pose(10,2);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));
	
	put_effect_on_char(19,12,1,2);
	set_character_pose(10,1);
	set_character_facing(10,3);
	run_animation_sound(69);
	set_character_pose(10,2);
	set_character_facing(10,4);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));
	
	put_effect_on_char(23,12,1,2);
	set_character_pose(11,1);
	set_character_facing(11,5);
	run_animation_sound(71);
	set_character_pose(11,2);
	set_character_facing(11,4);
	force_instant_terrain_redraw();
	kill_char(23,2,0);
	pause(1 * get_flag(290,0));
	
	put_effect_on_char(18,12,1,2);
	set_character_pose(11,1);
	run_animation_sound(71);
	set_character_pose(11,2);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));
	
	put_effect_on_char(16,12,1,2);
	set_character_pose(12,1);
	run_animation_sound(69);
	set_character_pose(12,2);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));
	
	put_effect_on_char(21,12,1,2);
	set_character_pose(12,1);
	set_character_facing(12,3);
	run_animation_sound(69);
	set_character_pose(12,2);
	set_character_facing(12,4);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));
	
	put_effect_on_char(12,12,1,2);
	set_character_pose(16,1);
	run_animation_sound(70);
	set_character_pose(16,2);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));
	
	put_effect_on_char(10,12,1,2);
	set_character_pose(17,1);
	run_animation_sound(70);
	set_character_pose(17,2);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));
	
	put_effect_on_char(11,12,1,2);
	set_character_pose(18,1);
	run_animation_sound(70);
	set_character_pose(18,2);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));
	
	text_bubble_on_char(13,"Fireball!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(13,"");
	set_character_pose(13,1);
	put_jagged_zap(char_loc_x(13),char_loc_y(13),16,26,0);
	put_boom_on_char(21,1,0);
	put_boom_on_char(16,1,0);
	put_boom_on_char(19,1,0);
	put_boom_on_char(32,1,0);
	put_boom_on_char(31,1,0);
	play_sound(-73);
	play_sound(-73);
	play_sound(-73);
	play_sound(-73);
	run_animation_sound(73);
	
	set_character_pose(13,2);
	kill_char(21,2,0);
	kill_char(16,2,0);
	kill_char(19,2,0);
	kill_char(31,2,0);
	
	text_bubble_on_char(14,"Shockwave!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(14,"");
	text_bubble_on_char(15,"No, Feodoric!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(15,"");
	text_bubble_on_char(15,"We don't want to hurt");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(15,"");
	text_bubble_on_char(15,"any innocent civilians!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(15,"");
	force_instant_terrain_redraw();
	
	message_dialog("You could swear that he looked at you as he said this.","");
	
	text_bubble_on_char(14,"Right.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(14,"");
	text_bubble_on_char(14,"Fire Storm!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(14,"");
	set_character_pose(14,1);
	put_jagged_zap(char_loc_x(14),char_loc_y(14),19,27,0);
	put_boom_on_char(17,1,0);
	put_boom_on_char(20,1,0);
	put_boom_on_char(18,1,0);
	put_boom_on_char(22,1,0);
	put_boom_on_char(24,1,0);
	put_boom_on_char(28,1,0);
	put_boom_on_char(25,1,0);
	put_boom_on_char(26,1,0);
	put_boom_on_char(29,1,0);
	put_boom_on_char(27,1,0);
	play_sound(-73);
	play_sound(-73);
	play_sound(-73);
	play_sound(-73);
	play_sound(-73);
	play_sound(-73);
	play_sound(-73);
	play_sound(-73);
	play_sound(-73);
	run_animation_sound(73);
	
	set_character_pose(14,2);
	kill_char(20,2,0);
	kill_char(18,2,0);
	kill_char(22,2,0);
	play_sound(26);
	kill_char(24,2,0);
	kill_char(28,2,0);
	kill_char(25,2,0);
	kill_char(26,2,0);
	kill_char(29,2,0);
	play_sound(26);

	text_bubble_on_char(14,"I gained a level!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(14,"");
	text_bubble_on_char(10,"Me too.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(10,"");
	text_bubble_on_char(14,"Freeloader.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(14,"");
	text_bubble_on_char(10,"Hey, I softened them up for you!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(10,"");
	text_bubble_on_char(15,"Hush, both of you!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(15,"");
	text_bubble_on_char(15,"Ice Bolt!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(15,"");
	set_character_pose(15,1);
	put_jagged_zap(char_loc_x(15),char_loc_y(15),char_loc_x(27),char_loc_y(27),1);
	put_boom_on_char(27,3,0);
	run_animation_sound(65);

	set_character_pose(14,2);
	force_instant_terrain_redraw();

	text_bubble_on_char(27,"Daemon!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	activate_hidden_group(2);
	text_bubble_on_char(27,"");
	set_character_pose(27,1);
	put_jagged_zap(char_loc_x(27),char_loc_y(27),char_loc_x(33),char_loc_y(33),4);
	put_boom_on_char(33,6,0);
	run_animation_sound(61);
	
	pause(5 * get_flag(290,0));

	message_dialog("Everyone pauses for a second. No one moves at all. Several people look at the warrior in the middle of the room.","");
	
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(15,"Jenneke!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(15,"");
	text_bubble_on_char(15,"A new turn started!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(15,"");
	text_bubble_on_char(15,"It's your move!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(15,"");
	text_bubble_on_char(10,"Oops, sorry.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(10,"");
	relocate_character(10,17,25);
	set_character_facing(10,3);
	force_instant_terrain_redraw();
	
	put_effect_on_char(32,12,1,2);
	set_character_pose(10,1);
	run_animation_sound(69);
	set_character_pose(10,2);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));
	
	kill_char(32,2,0);

	relocate_character(11,19,25);
	set_character_facing(11,3);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));
	
	put_effect_on_char(33,12,1,2);
	set_character_pose(11,1);
	set_character_facing(11,4);
	run_animation_sound(69);
	set_character_pose(11,2);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));
	
	put_effect_on_char(33,12,1,2);
	set_character_pose(11,1);
	run_animation_sound(69);
	set_character_pose(11,2);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));
	
	kill_char(33,2,0);

	set_character_facing(11,2);
	
	put_effect_on_char(17,12,1,2);
	set_character_pose(11,1);
	run_animation_sound(69);
	set_character_pose(11,2);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));
	
	kill_char(17,2,0);

	text_bubble_on_char(13,"Kill!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(13,"");
	set_character_pose(13,1);
	put_jagged_zap(char_loc_x(13),char_loc_y(13),char_loc_x(27),char_loc_y(27),1);
	put_boom_on_char(27,3,0);
	run_animation_sound(65);

	set_character_pose(13,2);
	kill_char(27,2,0);

	text_bubble_on_char(14,"Flame!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(14,"");
	set_character_pose(14,1);
	put_jagged_zap(char_loc_x(14),char_loc_y(14),char_loc_x(30),char_loc_y(30),0);
	put_boom_on_char(30,1,0);
	run_animation_sound(73);

	set_character_pose(14,2);
	kill_char(30,2,0);

	erase_char(10);
	erase_char(11);
	erase_char(12);
	erase_char(13);
	erase_char(14);
	erase_char(15);

	message_dialog("With the battle won, the adventurers head over to the next room with hardly a glance back at you. You hear a shout of, _We got it! The artifact is ours!_ and then their footsteps grow farther and farther away.","You hope their _artifact_ wasn't Machrone's box. That would be decidedly inconvenient.");

	text_bubble_on_char(2,"Was anyone else impressed");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(2,"");
	text_bubble_on_char(2,"by how they killed that rouge wizard?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(2,"");
	text_bubble_on_char(3,"Rogue wizard.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	text_bubble_on_char(2,"That's what I said. Rouge wizard.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(2,"");
	text_bubble_on_char(3,"But it's spelled...");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	text_bubble_on_char(3,"Never mind.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	force_instant_terrain_redraw();

	set_flag(6,1,3);
	}
break;

beginstate 14;
if ((get_flag(3,1) == 0) || (get_flag(3,1) == 5)) {
	block_entry(1);
	message_dialog("This spot sure is a mess. You avoid it.","");
	end();
	}
if (get_flag(6,5) == 0) {
	reset_dialog_preset_options(1);
	add_dialog_str(0,"Here, in this thick, mushy filth, you find a small, gold-colored box. It has the tell-tale emblem of a quill on it. It must be Machrone's box!",0);
	add_dialog_str(1,"You pick it up and examine it. There's no evidence of its contents. You shake it, but it makes no sound. You have no idea what is in it.",0);
	add_dialog_str(2,"What do you do?",0);
	if (run_dialog(1) == 2) {
		set_flag(6,5,1);
		change_spec_item(1,1);
		message_dialog("You pocket the box. Time to take it back to Machrone and collect your reward.","");
		}
	else
		block_entry(1);
	}
break;

beginstate 15;
if (get_flag(6,6))
	end();
i = 0;
while (char_ok(i) == 0)
	{i = i + 1; }
if (char_loc_y(i) <= 26) {
	set_flag(6,6,1);
	message_dialog("There is a secret passage here. You didn't notice it from the other side, but you can slip through now.","");
	}
else
	block_entry(1);
break;

beginstate 16;
if (get_flag(6,7) == 0) {
	set_flag(6,7,1);
	message_dialog("You hear a faint scratching noise. It sounds like tunneling chitrachs.","");
	}
break;

beginstate 17;
if (get_flag(6,8) == 0) {
	set_flag(6,8,1);
	message_dialog("You again hear the tunneling chitrachs that you heard before. They are much closer now. You proceed with your hands on your weapons.","");
	}
break;

beginstate 18;
if (get_flag(6,9) == 0) {
	set_flag(6,9,1);
	message_dialog("As you enter this small opening, you can hear the chitrachs emerging somewhere far away, attacking some other poor fools instead of you for a change.","What a relief.");
	}
break;

beginstate 19;
	message_dialog("Judging from the scrapes and blast marks, something sharp and important and probably magical was here before you arrived. It's gone now, though..","Hopefully this wasn't Machrone's box. That might still be nearby.");
break;

beginstate 20;
	inc_flag(6,10,1);
	
	if (get_flag(6,10) == 4) {
		message_dialog("The last goblin falls, and you try to calm your tear-soaked party member. After a while, she may come around, now that the goblins are no more. ","");
		set_flag(6,1,2);
		}
break;

beginstate 21;
if ((get_flag(3,1) != 1) && (get_flag(3,1) != 3)) {
	block_entry(1);
	message_dialog("Your third member speaks out suddenly. _Goblins live here! I don't like goblins! I don't like goblins at all! I won't go any farther into this awful cave, and none of you can make me!!_","You try to talk to her, but she is insistent. Without a compelling reason, you cannot proceed.");
	}
break;

